<?php

namespace app\common\validate\zbtask;


use app\common\library\BankMatch;
use app\common\model\Config;
use app\common\validate\BaseValidate;
use cszchen\citizenid\Parser;

class Import extends BaseValidate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'real_name|真实姓名'       => 'require|length:2,30',
        'identity_card|身份证号码'       => 'require|length:10,30|checkCard',
        'bank_card|账户'       => 'require|length:5,30|checkBank',
        'mobile|手机号'       => 'isMobile',
        'money|众包费'       => 'require|float|gt:0|checkMoney',
        'type|账户类型'       => 'require|in:0,1,2',
        'money_type|是否实发'       => 'require|in:1,2',
        'item|所得项目'       => 'require|length:0, 50',
        'task_id|所得项目'       => 'require|number',
    ];
    /**
     * 提示消息
     */
    protected $message = [
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => [],
        'edit' => [],
    ];

    /**检测身份证格式*/
    protected function checkCard($value,$rule,$data)
    {
        $parser = new Parser();
        $parser->setId($value);
        /*if (!$parser->isValidate()) {
            return '请正确填写身份证号码';
        } else {
            return true;
        }*/
        return true;
    }

    /**检测账户，只验证银行卡, 支付宝和微信号码未作判断*/
    protected function checkBank($value,$rule,$data) {
        if ($data['type'] == 0) {
            try {
                $bankMatch = BankMatch::instance();
                $bankMatch->match($value);
            } catch (\Exception $e) {
                return $e->getMessage();
            }
        }
        return true;
    }

    /**
     * 费用检测
     */
    protected function checkMoney($value,$rule,$data) {
        /*$limit = config('site.money_limit');
        if ($limit && $limit < $value) {
            return '打款金额超过限制金额';
        }*/

        return true;
    }
    
}
